package emulator.util.file;

import java.io.FileInputStream;
import java.io.IOException;

import emulator.hardware.memory.MemoryBlockInterface;

public class FileLoadStrategySkipPrefix implements FileLoadStrategy {
	
	int prefix;
	
	public FileLoadStrategySkipPrefix(int prefix_size)
	{
		prefix = prefix_size;
	}

	@Override
	public void loadToMemory(String file_name, MemoryBlockInterface memory,
							 int start_address, int block_size)
	{
		FileInputStream file = null;
		try
		{
			file = new FileInputStream(file_name);
			for (int i = 0; i < prefix; i++)
				file.read();
			memory.loadFromStream(file, start_address, block_size);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			if (file != null)
				try { file.close(); } catch (IOException e) {}
		}
	}

}
